const app = getApp()
let isshow = isshow;
var login_id;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    yuanyinIndex: 0,
    yuanyin: [],
    isshow: false,
    fIndex: 2,
    jj_num: 0,
    list: [],
    detail:'',
    YuYueID: '',
    ZiGeID:'',
    yuanyin_neirong:'',
    yuanyin_leixing:'',
    yuanyin_neirong:'',
    yuanyin_leixing_id:0
  },

  jj_input: function (e) {
    this.setData({
      jj_num: e.detail.cursor
    });
    this.setData({
      yuanyin_neirong: e.detail.value,
      yuanyin_neirong: e.detail.value,
    })
  },

  isshow:function(){
    self = this;
    self.setData({
      isshow: (!self.data.isshow) 
    })
  },

  //选择取消原因
  yuanyinChange: function (e) {
    this.setData({     
      yuanyinIndex: e.detail.value,
      yuanyin_leixing: this.data.yuanyin[e.detail.value].name,
      yuanyin_leixing_id: this.data.yuanyin[e.detail.value].id,
    })
  },


  //管理员审核 data-type=2 通过  1驳回
  shenhe: function (res) {
    console.log(res.currentTarget.dataset)
    var that = this;
    var YuYueID = this.data.YuYueID
    console.log(YuYueID)

    var ShenHeLeiXing = 2
    var ZhongDuanLeiXing = 3
    var noPassReason = this.data.yuanyin_neirong
    if (res.currentTarget.dataset.type == 1 && noPassReason == '') {
      wx.showToast({
        title: '请填写原因',
        icon: 'none',
        image: '',
        duration: 2000,
        mask: true,
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '是否确定该操作？',
        showCancel: true, //是否显示取消按钮
        cancelText: "否", //默认是“取消”
        cancelColor: 'skyblue', //取消文字的颜色
        confirmText: "是", //默认是“确定”
        confirmColor: 'skyblue', //确定文字的颜色
        success: function (res) {
          if (!res.cancel) {
            wx.request({
              url: app.globalData.apiUrl + 'IS05/HIS050100.ASHX?Method=GetShengHeXinXi&LoginID=' + login_id + '&YuYueID=' + YuYueID + '&ShenHeLeiXing=' + ShenHeLeiXing + '&noPassReason=' + noPassReason + '&ZhongDuanLeiXing=3',
              method: "GET",
              data: {},
              success: function (res) {
                console.log(res)
                wx.showToast({
                  title: res.data.retMsg,
                  icon: 'success',
                  image: '',
                  duration: 2000,
                  mask: true,
                })
                setTimeout(function () {
                  wx.redirectTo({
                    url: '/pages/list_sysyy/list_sysyy?cateid=1'
                  })
                }, 2000)
              }
            })
          }
        },
        fail: function (res) { }, //接口调用失败的回调函数
        complete: function (res) { }, //接口调用结束的回调函数（调用成功、失败都会执行）
      })
    }
  },

  //学员自己取消
  quxiao: function (res) {
    var that = this;
    var YuYueID = this.data.YuYueID

    var ZhongDuanLeiXing = 3
    var QuXiaoYuanYinFenLeiMingCheng = this.data.yuanyin_leixing
    var QuXiaoYuanYinFenLei = this.data.yuanyin_leixing_id
    var QuXiaoYuanYin = this.data.yuanyin_neirong

    if (QuXiaoYuanYinFenLei == 0 && QuXiaoYuanYin == '') {
      wx.showToast({
        title: '请填写具体内容',
        icon: 'none',
        image: '',
        duration: 2000,
        mask: true,
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '是否确定该操作？',
        showCancel: true, //是否显示取消按钮
        cancelText: "否", //默认是“取消”
        cancelColor: 'skyblue', //取消文字的颜色
        confirmText: "是", //默认是“确定”
        confirmColor: 'skyblue', //确定文字的颜色
        success: function (res) {
          if (!res.cancel) {
            that.goquxiao(YuYueID, login_id, QuXiaoYuanYinFenLei, QuXiaoYuanYinFenLeiMingCheng, QuXiaoYuanYin);
          }
        },
        fail: function (res) { }, //接口调用失败的回调函数
        complete: function (res) { }, //接口调用结束的回调函数（调用成功、失败都会执行）
      })
    }

  },

  goquxiao(YuYueID, login_id, QuXiaoYuanYinFenLei, QuXiaoYuanYinFenLeiMingCheng, QuXiaoYuanYin) {
    var that = this;

    wx.request({
      url: app.globalData.apiUrl + 'IS02/HIS020100.ashx?Method=ShiYanShiYuYueQuXiao&LoginID=' + login_id + '&YuYueID=' + YuYueID + '&QuXiaoYuanYinFenLei=' + QuXiaoYuanYinFenLei + '&QuXiaoYuanYinFenLeiMingCheng=' + QuXiaoYuanYinFenLeiMingCheng + '&QuXiaoYuanYin=' + QuXiaoYuanYin+ '&ZhongDuanLeiXing=3',
      method: "GET",
      data: {},
      success: function (res) {
        console.log(res)
        wx.showToast({
          title: res.data.retMsg,
          icon: 'success',
        })
        setTimeout(function () {
          wx.redirectTo({
            url: '/pages/list_sysyy/list_sysyy?cateid=1'
          })
        }, 2000)

      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (res){
    var YuYueID = res.yuyueid;
    login_id = wx.getStorageSync('user') == "" ? -999 : wx.getStorageSync('user').UserID;
    console.log(res)
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'IS02/HIS020101.ashx?Method=GetYuYueShiYanShiInfo&LoginID=' + login_id + '&YuYueID=' + res.yuyueid,
      method: "GET",
      data: {},
      success: function(res){
        that.setData({          
          detail: res.data.retData.XiangXiXinXi[0],
          YuYueID: YuYueID,
        }) 
      }
    })     
    wx.request({
      url: app.globalData.apiUrl + 'IS05/HIS050100.ashx?Method=GetQuXiaoYuanYin&YuanYinType=2',
      method: "GET",
      data: {},
      success: function (res) {  
        var yuanyin=[]
        for (var i=0; i < res.data.retData.QuXiaoYuanYin.length;i++){
          var obj = {};
          obj.id = res.data.retData.QuXiaoYuanYin[i].ZiDianZhiID
          obj.name = res.data.retData.QuXiaoYuanYin[i].ZiDianZhiMingCheng
          yuanyin.push(obj);
        }
        that.setData({
          yuanyin: yuanyin,
          yuanyin_leixing: yuanyin[0].name,
          yuanyin_id: yuanyin[0].id,
        })
      }
    }) 
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})